package com.xiaoshuidi.cloud.framework.pay.core.client.impl.tongshangyun.miniapp;

import com.allinpay.sdk.bean.BizParameter;
import com.xiaoshuidi.cloud.framework.pay.core.client.PayCommonResult;
import com.xiaoshuidi.cloud.framework.pay.core.client.dto.PayOrderUnifiedReqDTO;
import com.xiaoshuidi.cloud.framework.pay.core.client.dto.PayOrderUnifiedRespDTO;
import com.xiaoshuidi.cloud.framework.pay.core.client.impl.tongshangyun.TongshangyunClientConfig;
import com.xiaoshuidi.cloud.framework.pay.core.client.impl.tongshangyun.TongshangyunCodeMapping;
import com.xiaoshuidi.cloud.framework.pay.core.client.impl.tongshangyun.enums.TongshangyunApiType;
import com.xiaoshuidi.cloud.framework.pay.core.enums.PayChannelEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;

@Slf4j
public class TongshangyunWXMiniAppPayClient extends AbstractTongshangyunMiniAppPayClient {
    public TongshangyunWXMiniAppPayClient(Long channelId, TongshangyunClientConfig config) {
        super(channelId, PayChannelEnum.TONGSHANGYUN_WX_MINIAPP.getCode(), config, new TongshangyunCodeMapping());
    }

    @Override
    protected <T> PayCommonResult<PayOrderUnifiedRespDTO<T>> doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) throws Throwable {
        BizParameter param = baseParams(reqDTO);
        // 支付方式
        // 收银宝支付宝小程序收银台支付
        HashMap<String, Object> wechatpayMiniprogramCashierVsp = new HashMap<>();
        wechatpayMiniprogramCashierVsp.put("amount", reqDTO.getAmount());
        wechatpayMiniprogramCashierVsp.put("limitPay", "");
        // 组装支付方式
        HashMap<String, Object> payMethod = new HashMap<>();
        payMethod.put("WECHATPAY_MINIPROGRAM_CASHIER_VSP", wechatpayMiniprogramCashierVsp);
        param.put("payMethod", payMethod);
        log.info("通商云微信支付请求数据：{}", param);
        return call(TongshangyunApiType.CONSUME_APPLY.getApi(), param,reqDTO.getMerchantOrderId());
    }

}
